package edu.hbsi.Exercise;
import java.util.LinkedList;
        import java.util.Scanner;
public class KTVchooseLinkedList {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        LinkedList<String> songList = new LinkedList<>();
        songList.add("稻香");
        songList.add("夜曲");
        songList.add("夜的第七章");
        songList.add("听妈妈的话");
        songList.add("龙卷风");

        while (true) {
            System.out.println("------------------欢迎来到点歌系统点歌系统------------------");
            System.out.println("0.添加歌曲至列表");
            System.out.println("1.将歌曲置顶");
            System.out.println("2.将歌曲前移一位");
            System.out.println("3.退出");
            System.out.println("初始歌曲列表：" + songList);
            System.out.print("请输入要执行的操作序号：");

            int operation = scanner.nextInt();
            scanner.nextLine(); // 清除换行符

            if (operation == 0) {
                System.out.print("请输入要添加的歌曲名称：");
                String songName = scanner.nextLine();
                songList.add(songName);
                System.out.println("已添加歌曲：" + songName);
            } else if (operation == 1) {
                System.out.print("请输入要置顶的歌曲名称：");
                String songName = scanner.nextLine();
                if (songList.contains(songName)) {
                    songList.remove(songName);
                    songList.addFirst(songName);
                    System.out.println("已将歌曲" + songName + "置顶");
                } else {
                    System.out.println("歌曲列表中不存在该歌曲");
                }
            } else if (operation == 2) {
                System.out.print("请输入要置前的歌曲名称：");
                String songName = scanner.nextLine();
                int index = songList.indexOf(songName);
                if (index != -1 && index != 0) {
                    songList.remove(songName);
                    songList.add(index - 1, songName);
                    System.out.println("已将歌曲" + songName + "置前一位");
                } else {
                    System.out.println("歌曲列表中不存在该歌曲或该歌曲已在最前面");
                }
            } else if (operation == 3) {
                System.out.println("您已退出系统");
                break;
            } else {
                System.out.println("输入的操作序号无效，请重新输入");
            }
        }
    }
}
